'use strict';

const path = require('path');
const webpack = require('webpack');
const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin');
const MiniCssEtractPlugin = require('mini-css-extract-plugin');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
module.exports = {
    mode: 'production',
    entry: {
        "app": './src/index.js',
        "search": "./src/search.js"
    },
    output: {
        path: path.join(__dirname, 'dist'),
        filename: '[name][chunkhash:8].js'
    },
    module: {
        rules: [
            {
                test: /.js$/,
                use: 'babel-loader'
            },
            {
                test: /.css$/,
                use: [
                    MiniCssEtractPlugin.loader,
                    "css-loader",
                    {
                        'loader': 'postcss-loader',
                        'options': {
                            plugins: ()=> [
                                require('autoprefixer')({
                                    "overrideBrowserslist": ['last 20 version', '>1%', 'ios 7']
                                })
                            ]
                        }
                    }
                ]
            },
            {
                test: /.(png|jpg|gif|jpeg|woff|woff2|eot|tff)$/,
                use: {
                    "loader": 'url-loader',
                    "options": {
                        limit: 10240
                    }
                }
            }
        ]
    },
    plugins: [
        new OptimizeCSSAssetsPlugin({
            assetNameRegExp: /\.css$/g,
            cssProcessor: require('cssnano')
        }),
        new MiniCssEtractPlugin({
            filename: '[name]_[contenthash:8].css'
        }),
        new CleanWebpackPlugin()
    ],
    ,
    resolve: {
        alias: {
            '@': resolve('src')
        }
    }
}